package cn.edu.hhu.service.Impl;

import cn.edu.hhu.Bean.Admin;
import cn.edu.hhu.Bean.Student;
import cn.edu.hhu.Bean.Teacher;
import cn.edu.hhu.DAO.Admin_infoDao;
import cn.edu.hhu.DAO.AttendanceTaskDao;
import cn.edu.hhu.DAO.StudentDao;
import cn.edu.hhu.DAO.Teacher_infoDao;
import cn.edu.hhu.DAO.impl.Admin_infoDaoImpl;
import cn.edu.hhu.DAO.impl.AttendanceTaskDaoImpl;
import cn.edu.hhu.DAO.impl.StudentDaoImpl;
import cn.edu.hhu.DAO.impl.Teacher_infoDaoImpl;
import cn.edu.hhu.service.AdminService;
import org.junit.Test;

import java.sql.Timestamp;
import java.util.List;

/**
 * @anthor: lddd
 * @date: 2020/5/17 - 9:04
 * @description:
 **/
public class AdminServiceImpl implements AdminService {
    private Admin_infoDao admin_infoDao = new Admin_infoDaoImpl();
    private StudentDao studentDao = new StudentDaoImpl();
    private Teacher_infoDao teacherDao = new Teacher_infoDaoImpl();

    /**
     * 根据提供的admin验证账号密码
     * @param admin
     * @return 正确返回全部身份信息，错误返回null
     */
    @Override
    public Admin login(Admin admin) {
        return admin_infoDao.findAdminByIdAndPassword(admin.getAid(), admin.getPwd());
    }

    /**
     * 查询所有学生
     * @return 学生列表
     */
    @Override
    public List<Student> queryAllStudent() {
        return studentDao.findAllStudent();
    }

    /**
     * 根据sid删除一位学生信息
     * @param sid
     * @return 是否成功
     */
    @Override
    public boolean deleteStudent(String sid) {
        return studentDao.deleteStudentByID(sid);
    }

    /**
     * 将学号为sid的学生账户密码设为newPassword
     * @param sid
     * @return 是否成功
     */
    @Override
    public boolean modifyStudentPassword(String sid, String newPassword) {
        return studentDao.changeStudentPwd(sid, newPassword);
    }

    /**
     * 管理员置入一个未激活的学生账户
     * @param sid
     * @param sname
     * @return 是否成功
     */
    @Override
    public boolean addSingleStudent(String sid, String sname) {
        Student student = new Student();
        student.setSid(sid);
        student.setSname(sname);
        return studentDao.insertSingleStudent(student);
    }

    /**
     * 管理员置入一个未激活的教师账户
     * @param tid
     * @param tname
     * @return
     */
    @Override
    public boolean addSingleTeacher(String tid, String tname) {
        Teacher teacher = new Teacher();
        teacher.setTid(tid);
        teacher.setTname(tname);
        return teacherDao.insertSingleTeacher(teacher);
    }

    /**
     * 查询所有教师
     * @return 教师列表
     */
    @Override
    public List<Teacher> queryAllTeacher() {
        return teacherDao.findAllTeacher();
    }

    /**
     * 根据tid删除教师账户
     * @param tid
     * @return 是否成功
     */
    @Override
    public boolean deleteTeacher(String tid) {
        return teacherDao.deleteTeacherByID(tid);
    }

    /**
     * @param tid
     * @param newPassword
     * @return 将tid的教师账户密码设为newPassword
     */
    @Override
    public boolean modifyTeacherPassword(String tid, String newPassword) {
        return teacherDao.changeTeacherPassword(tid, newPassword);
    }

    @Test
    public void test() {
        AdminService adminService = new AdminServiceImpl();
        adminService.addSingleTeacher("00000010", "我");
    }
}
